using System;

namespace AntEater.Runtime.Services
{
    /// <summary>
    /// Provides an abstract runtime service
    /// </summary>
    public abstract class RuntimeServiceBase : IRuntimeService, IDisposable
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="RuntimeServiceBase"/> class.
        /// </summary>
        protected RuntimeServiceBase() {
            this._isReusable = true;
        }

        private RuntimeServiceContext _context;

        /// <summary>
        /// Gets the context.
        /// </summary>
        /// <value>The context.</value>
        protected RuntimeServiceContext Context {
            get { return _context; }
        }

        private bool _isReusable;

        /// <summary>
        /// Gets a value indicating whether this instance is reusable.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is reusable; otherwise, <c>false</c>.
        /// </value>
        public virtual bool IsReusable {
            get { return _isReusable; }
        }

        private bool _isShutdown;

        /// <summary>
        /// Gets a value indicating whether this instance is shutdown.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is shutdown; otherwise, <c>false</c>.
        /// </value>
        public bool IsShutdown {
            get { return _isShutdown; }
        }

        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <param name="context">The context.</param>
        public virtual void Initialize(RuntimeServiceContext context) {
            this._context = context;
        }

        /// <summary>
        /// Shutdowns this instance.
        /// </summary>
        public virtual void Shutdown() {
            this._isShutdown = true;
            this.Dispose();
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose() {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// Disposes the specified disposing.
        /// </summary>
        /// <param name="disposing">if set to <c>true</c> [disposing].</param>
        protected virtual void Dispose(bool disposing) {
            if (disposing == true) {
            }
        }
    }
}
